//
//  MYRetweetView.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/8/1.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

let homeCellMargin = 10

class MYRetweetView: UIView {
    
    /** 约束 */
    var constraint: Constraint?
    
    var retweetViewModel: MYHomeCellViewModel? {
        
        didSet {
            
            contentLabel.text = retweetViewModel?.statusModel?.retweeted_status?.text
            
            constraint?.uninstall()
            
            /** 展示图片 */
            if let pic_urls = retweetViewModel?.statusModel?.retweeted_status?.pic_urls where pic_urls.count > 0 {
                /** 展示图片 */
                pictureView.hidden = false
                /** 更新约束 */
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.constraint = make.bottom.equalTo(pictureView.snp_bottom).constraint
                })
                /** 传入模型 */
                pictureView.pic_urls = pic_urls
            } else {
                /** 隐藏图片 */
                pictureView.hidden = true
                /** 更新约束 */
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.constraint = make.bottom.equalTo(contentLabel.snp_bottom).constraint
                })
            }
        }
    }
    

    /** 构造 */
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

   
    private func setUpUI() {
    
        backgroundColor = UIColor.yellowColor()
        
        addSubview(contentLabel)
        addSubview(pictureView)
    
        /** 约束 */
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(homeCellMargin)
//            make.right.equalTo(self.snp_right)
            make.top.equalTo(contentLabel.snp_bottom)
            make.width.equalTo(100)
            make.height.equalTo(100)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            self.constraint = make.bottom.equalTo(pictureView.snp_bottom).constraint
        }
    }
    
    /** 懒加载 */
    /** 内容按钮 */
    private lazy var contentLabel: UILabel = {
    
        let label = UILabel()
        
        label.text = "转发微博"
        
        return label
    }()
    
    /** 图片视图 */
    private lazy var pictureView: MYPictureView = MYPictureView()
}
